/*
 * Copyright 2010 Cedric Priscal
 *
 * This file is part of stupid-avr-robot.
 *
 * stupid-avr-robot is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * stupid-avr-robot is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with stupid-avr-robot.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Usart.h"

Usart::Usart() {
    mListener = 0;
}

void Usart::registerListener(UsartListener *listener) {
	mListener = listener;
}

void Usart::send(const unsigned char *buffer, char size) {
	while(size > 0) {
		send(*buffer++);
		size--;
	}
}

void Usart::send(unsigned short s) {
    char i;
    for (i=12; i>=0; i-=4) {
        unsigned char digit = (s >> i) & 15;
        if (digit < 10) {
            send((unsigned char)('0' + digit));
        } else {
            send((unsigned char)(('a'-10) + digit));
        }
    }
}

void Usart::send(const char *txt) {
    while(*txt != 0) {
        send((unsigned char)*txt++);
    }
}

